<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<!DOCTYPE html>
<html lang="en">
<head>
<title><s:message code="app.title" /></title>
<%@ include file="Include.jsp"%>
<script type="text/javascript">
	
	$(document).ready(function() {
		var oTable = $('#contactTable').dataTable( {
			 	"bDestroy": true,
		        "bProcessing": false,
		        "iDisplayLength": 10,
		        "bFilter": false,
		        "bLengthChange": false,
		        "aoColumnDefs": [
		          { 'bSortable': false, 'aTargets': [0] }
		       	]
		 	} );
		
		$('#addContact').click(function(){
			$('#contactListForm').attr('action','AddContact');
			$('#contactListForm').attr('method','get');
			$('#contactListForm').submit();
		});

		
	});
	
	function edit(contactId){
		$('#contactEditForm').attr('action','EditContact?contactId='+contactId);
		
		$('#contactId').val(contactId);
		
		$('#contactEditForm').attr('method','get');
		$('#contactEditForm').submit();
	}
	
	function manageAddress(contactId){
		$('#contactEditForm').attr('action','ListContactAddress?contactId='+contactId);
		
		$('#contactId').val(contactId);
		
		$('#contactEditForm').attr('method','get');
		$('#contactEditForm').submit();
	}
	
</script>
</head>
<body>
	<div class="container">
		<%@ include file="Menu.jsp"%>
		<h2><s:message code="contactForm.listheader" /></h2>
		<hr>
		<form:form id="contactEditForm" >
			<input type="hidden" id="contactId" name="contactId" />
		</form:form>
		<form:form id="contactListForm" >
		<table class="table table-hover table-bordered" id="contactTable">
				<thead>
					<tr>
						<th><s:message code="contactForm.categoryid" /></th>
						<th><s:message code="contactForm.fullname" /></th>
						<th><s:message code="contactForm.shortname" /></th>
						<th><s:message code="contactForm.creditterms" /></th>
						<th><s:message code="contactForm.comments" /></th>
						<th><s:message code="app.action" /></th>
					</tr>
				</thead>
				
				<tbody>
					<c:forEach items="${contactList}" var="contact" >
						<tr>
							<td>
								<c:out value="${contact.categoryname}"></c:out>
							</td>
							<td>
								<c:out value="${contact.fullname}"></c:out>
							</td>
							<td>
								<c:out value="${contact.shortname}"></c:out>
							</td>
							<td>
								<c:out value="${contact.creditterms}"></c:out>
							</td>
							<td>
								<c:out value="${contact.comments}"></c:out>
							</td>
							<td>
								<a href="#" onclick="javascript: edit('${contact.contactid}');" >Edit</a>
								|
								<a href="#" onclick="javascript: manageAddress('${contact.contactid}');" >Manage Address</a>
							</td>
						</tr>
					</c:forEach>
				</tbody>
		</table>
		<br>
		<br>
		<br>
		<button class="btn btn-primary" type="button" id="addContact"><s:message code="contactForm.addheader" /></button>
		</form:form>
		 <%@ include file="Footer.jsp"%>
	</div>
</body>
</html>